#include <libdswserver/dswmsgserver.h>
#include <libdswsession/dswlanmsgsession.h>

CDswmsgserver::CDswmsgserver(LPST_ENV_T pEnv, int nPort)
: CDswtcpserver_base(pEnv, nPort)
{
	LOG4CPLUS_DEBUG(log_dsw, "Create CDswmsgserver class! server port [ " << nPort << " ]");
}

CDswmsgserver::~CDswmsgserver()
{
	LOG4CPLUS_DEBUG(log_dsw, "Destroy CDswmsgserver class!");
}

void CDswmsgserver::OnAccept(evutil_socket_t fd, struct sockaddr *address, int socklen)
{
	char sKey[64];
	struct sockaddr_in *client = (struct sockaddr_in*)address;
	sprintf(sKey, "%s:%d", inet_ntoa(client->sin_addr), ntohs(client->sin_port));
	new  CDswlanmsgsession(m_pEnv, evconnlistener_get_base(m_pListener), fd, sKey);
}

